package dummy.virussim

import mars.ns.core._
import mars.ns.HasState
import mars.ns.events.ChangeEvent

class InfectEvent[T <: Node with InfectedState](net:Network[T], n2 : T) extends ChangeEvent[T]{
	def getNode : T = n2
	var executed:Boolean = false
	def executeAction : List[T] = {
	    var changedNodes:List[T] = Nil
	    if(n2.isHealthy) {
	        n2.setInfected
	        changedNodes = n2::changedNodes
	        n2.getLinkedObjects().foreach(arg => 
	            arg match{
	                case arg :T => {
	                    val event = new InfectEvent[T](net, arg)
	                    changedNodes = changedNodes:::event.executeAction	                    
	                }
	                case _ =>
	                })
	            
	    }
	    executed = true
	    return changedNodes
	}
	def nodeChanged : Boolean = {
	    return executed
	}
    def linkAdded : Boolean = {
        return false
    }
}